package com.kai.steering.data.service.entity.vo;

import com.kai.steering.data.service.entity.domainObject.AnswerDO;
import com.kai.steering.data.service.entity.domainObject.KnowledgeDO;
import com.kai.steering.data.service.entity.domainObject.NoteDO;
import com.kai.steering.data.service.entity.domainObject.QuestionDO;
import com.kai.steering.data.service.entity.po.QuestionDetails;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <pre>
 * 题目 VO对象
 * </pre>
 *
 * @author kai
 * @date 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "QuestionVO对象", description = "题目业务视图")
public class QuestionVO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "题目id")
    private String questionId;
    @ApiModelProperty(value = "题目")
    private String question;
    @ApiModelProperty(value = "题目详情")
    private String questionDetails;
    @ApiModelProperty(value = "答案详情")
    private List<AnswerVO> answerVO;
    @ApiModelProperty(value = "创建人管理员id或者用户id")
    private String founder;
    @ApiModelProperty(value = "创建时间")
    private Date creationDatetime;
    @ApiModelProperty(value = "题目类型分类")
    private ClassificationVO classificationVO;
    @ApiModelProperty(value = "知识点 以,分割")
    private List<KnowledgeVO> knowledgeVOS;
    @ApiModelProperty(value = "存在0删除1")
    private Integer usable;
    @ApiModelProperty(value = "删除日期")
    private Date deleteDatetime;
    @ApiModelProperty(value = "笔记")
    private NoteVO noteVO;
    @ApiModelProperty(value = "做题次数")
    private Integer problemNumber;
    @ApiModelProperty(value = "错误次数")
    private Integer errorNumber;
    @ApiModelProperty(value = "标准答案")
    private AnswerVO standardAnswer;
    @ApiModelProperty(value = "收藏")
    private  String collection;
    public QuestionVO(QuestionDO questionDO) {
        this.questionId = questionDO.getQuestionId();
        this.question = questionDO.getQuestion();
        if (questionDO.getQuestionDetailsDO() != null) {
            this.questionDetails = questionDO.getQuestionDetailsDO().getContent();
        }

        if (questionDO.getAnswerDO() != null) {
            this.answerVO = questionDO.getAnswerDO().stream().map(answerDO -> {
                return new AnswerVO(answerDO);
            }).collect(Collectors.toList());
        }

        if (questionDO.getStandardAnswer()!=null){
            this.standardAnswer=new AnswerVO(questionDO.getStandardAnswer());
        }

        this.founder = questionDO.getFounder();
        this.creationDatetime = questionDO.getCreationDatetime();
        this.classificationVO = new ClassificationVO(questionDO.getClassificationDO());

        if (questionDO.getKnowledgeDOs() != null) {
            this.knowledgeVOS = questionDO.getKnowledgeDOs().stream().map(knowledgeDO -> {
                return new KnowledgeVO(knowledgeDO);
            }).collect(Collectors.toList());
        }

        this.usable = questionDO.getUsable();
        this.deleteDatetime = questionDO.getDeleteDatetime();
        if (questionDO.getUserQuestionDO() != null) {

            this.problemNumber = questionDO.getUserQuestionDO().getProblemNumber();
            this.errorNumber = questionDO.getUserQuestionDO().getErrorNumber();
            this.collection = questionDO.getUserQuestionDO().getCollection();

            if (questionDO.getUserQuestionDO().getNoteDO() != null) {
                this.noteVO = new NoteVO(questionDO.getUserQuestionDO().getNoteDO());
            }
        }

    }

    public static List<QuestionVO> convertWarehouseVOS(List<QuestionDO> questionDOs) {
        List<QuestionVO> collect = questionDOs.stream().map(questionDO -> {
            return new QuestionVO(questionDO);
        }).collect(Collectors.toList());
        return collect;
    }
}